import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import NProgress from 'nprogress'

Vue.use(VueRouter);


const routes = [
  {
    path: '/',
    component: Login
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  }
];

const router = new VueRouter({
  mode:'history',
  routes:routes
});

// 路由全局前置守卫触发
/**
 * to 前往的路由配置
 * from 当前的路由
 * next 回调函数必须执行
 */
router.beforeEach((to, from, next) => {
  NProgress.start()
  // 获取动态路由配置
  // routesConfig = store.getters.ROUTERS_CONFIG
  // routes[2].children = routesConfig
  //
  // console.log(routes)
  next() // 必须执行
})
router.afterEach((to,from)=>{
  NProgress.done()
})

export default router
